<template>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
    :visible.sync="visible"
    :before-close="cancel"
    class="JNPF-dialog JNPF-dialog_center"
    lock-scroll
    width="80%"
  >
  <el-row class="JNPF-common-search-box" :gutter="16">
      <el-form @submit.native.prevent ref="elForm" :model="dataForm" :rules="rules">

        <el-col :span="8">
          <el-form-item label="报告单号" class="required" prop="fbillno">
            <el-input v-model="dataForm.fbillno" disabled/>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="报告日期" class="required" prop="forddate" >
            <el-date-picker
              v-model="dataForm.forddate"
              type="date"
              placeholder="选择日期" >
              </el-date-picker>
          </el-form-item>
          </el-col>

          <el-col :span="8">
          <el-form-item label="报告状态" class="required" prop="forduser" >
            <el-select v-model="dataForm.fbillstate" placeholder="请选择" >
              <el-option
                v-for="item in getListSpeakerId"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="8">
            <el-form-item label="实验人员" class="required" prop="frecuser" >
              <el-select v-model="dataForm.frecuser" placeholder="请选择" >
                <el-option
                  v-for="item in getListSpeakerId"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

        <el-col :span="8">
          <el-form-item label="委托单位" class="required" prop="forduser" >
            <el-select v-model="dataForm.forduser" placeholder="请选择" >
              <el-option
                v-for="item in getListSpeakerId"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

          <el-col :span="8">
            <el-form-item label="委托单号" class="required" prop="fsrcno">
              <el-input v-model="dataForm.fsrcno" />
            </el-form-item>
          </el-col>


          <el-col :span="8">
            <el-form-item label="样品名称">
              <el-input v-model="dataForm.fcatname"/>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="样品标签">
              <el-input v-model="dataForm.fcatno"/>
            </el-form-item>
          </el-col>

      </el-form>
    </el-row>

    <el-row class="JNPF-common-search-box" :gutter="16">
      <el-form @submit.native.prevent ref="elForm" :model="dataForm" :rules="rules">
        <el-col :span="8">
          <el-upload
            class="avatar-uploader"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
         </el-upload>
        </el-col>
     </el-form>
    </el-row>

    <span slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button  v-if="insertorupdate" type="primary" v-loading="loading">确 定</el-button>
      <el-button v-else type="primary"  v-loading="loading">修 改</el-button>
    </span>
  </el-dialog>
</template>

<style>
  .addbox{
    text-align: center;
    padding: 10px 0;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

<script>
import jnpf from "@/utils/jnpf"
export default {
  data() {
    return {
        imageUrl: '',
        title:"新增",
        list2:[{  "FENTRYID":1,
                "FCATNO": "100001",
                "FCATNAME": "实验猪配合饲料",
                "FNUM":"24121500001",
                "FMEMO":""
              },
              { "FENTRYID":2,
                "FCATNO": "100001",
                "FCATNAME": "实验猪配合饲料",
                "FNUM":"24121500002",
                "FMEMO":""
              },
              { "FENTRYID":3,
                "FCATNO": "100001",
                "FCATNAME": "实验猪配合饲料",
                "FNUM":"24121500003",
                "FMEMO":""
              }],
        catlist:[],
        fdangerlist:[],
        dataForm:{
          fbillno:"H2412160005",
          forddate:"2024-12-16",
          forduser:"上海全是肉供应链管理有限公司",
          frecuser:"曹操",
          fcatno:"24121500001",
          fcatname:"实验猪配合饲料",
          fsrcno:"P2412160005",
          fpiececount:20,
          ftotalamt:5900.00,
          fbillstate:"登记中"
        },
      loading:false,
      visible:false,
      insertorupdate:true
    };
  },
  created() {
  },
  mounted() {},
  methods: {
    handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },
    //
    init(id){
      this.dataForm.FCATNO= id || ''
        if(this.dataForm.FCATNO)
        {
            this.title="修改"
           this.insertorupdate=false;
        }
        else
        {
          this.insertorupdate=true;
            this.title="新增";
        }
        this.visible=true;
    },
    //
    cancel(){
        this.$refs.elForm.resetFields();
        this.visible=false;
    },
  },
};
</script>
